#include "../Common/httplib.h"
#include "Controller.hpp"
#include "Model.hpp"
int main()
{
  httplib::Server server;
  OJ::Controller ctrl;

  // 获取所有的题目列表
  server.Get("/all_questions", [&ctrl](const httplib::Request &req, httplib::Response &resp)
             {
        //返回一张包含有所有题目的html网页
        std::string html;
        ctrl.getAllQuestions(html);
        //用户看到的是什么呢？？网页数据 + 拼上了题目相关的数据
        resp.set_content(html, "text/html; charset=utf-8"); });
  // 用户查询某一个题号时，返回该题的详细信息
  server.Get(R"(/question/(\d+))", [&ctrl](const httplib::Request &req, httplib::Response &resp)
             {
        int number = std::stoi(req.matches[1]);
        std::string html;
        ctrl.getQuestion(number, html);
        resp.set_content(html, "text/html; charset=utf-8"); });

  server.set_base_dir("./wwwroot");
  server.listen("0.0.0.0", 8080);
  return 0;
}